package com.syg.servlet08_getRespHTML;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import java.io.IOException;

/**
 * 由于web Httpserver 是多线程执行服务端程序，所以buffer应该分线程来存取，这样大家才能不互相干扰。所以buffer需要实现TreadLocal接口。
 */
public class _03_ServletOutputStreamProxy extends ServletOutputStream {
    private ServletOutputStream obj;
    public _03_ServletOutputStreamProxy(ServletOutputStream obj){
        this.obj = obj;
    }
    //截获写内容写入buffer
    public void write(int b) throws IOException {
        Integer it = new Integer(b);
        _04_HtmlBuffer.addStr(new String(new byte[]{it.byteValue()}));
        obj.write(b);
    }

    @Override
    public boolean isReady() {
        return false;
    }

    @Override
    public void setWriteListener(WriteListener writeListener) {

    }
}
